package net.csdn.business.notify.handler.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.csdn.business.notify.common.enums.ResultCodeEnum;
import net.csdn.business.notify.common.exception.BusinessException;
import net.csdn.business.notify.common.mapper.NotifyRemindRecordMapper;
import net.csdn.business.notify.common.model.dto.UpdateNotifyRemindRecordDTO;
import net.csdn.business.notify.common.model.entity.NotifyRemindRecord;
import net.csdn.business.notify.common.model.query.NotifyRemindRecordQuery;
import net.csdn.business.notify.common.model.vo.NotifyRemindRecordVO;
import net.csdn.business.notify.handler.service.INotifyRemindRecordService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * 通知中心-用户通知记录Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-11-27
 */
@Service
public class NotifyRemindRecordServiceImpl extends ServiceImpl<NotifyRemindRecordMapper, NotifyRemindRecord> implements INotifyRemindRecordService
{

    /**
     * 分页查询通知中心-用户通知记录列表
     *
     * @param query 通知中心-用户通知记录
     * @return 通知中心-用户通知记录
     */
    @Override
    public Page<NotifyRemindRecordVO> findPageList(NotifyRemindRecordQuery query) {
        //获得Page对象
        Page<NotifyRemindRecordVO> page = query.getPage();
        List<NotifyRemindRecordVO> pageList=baseMapper.findPageList(page,query);
        page.setRecords(pageList);
        return page;
    }

    /**
     * 根据id查询通知中心-用户通知记录
     * 
     * @param id 通知中心-用户通知记录主键
     * @return 通知中心-用户通知记录
     */
    @Override
    public NotifyRemindRecordVO selectNotifyRemindRecordById(String id)
    {
        NotifyRemindRecordVO notifyRemindRecordVO=baseMapper.selectNotifyRemindRecordById(id);
        if(notifyRemindRecordVO==null){
            throw new BusinessException(ResultCodeEnum.PARAMETER_ERROR_CUSTOM,"id");
        }
        return notifyRemindRecordVO;
    }

    /**
     * 查询通知中心-用户通知记录列表
     * 
     * @param query 通知中心-用户通知记录
     * @return 通知中心-用户通知记录
     */
    @Override
    public List<NotifyRemindRecordVO> selectNotifyRemindRecordList(NotifyRemindRecordQuery query)
    {
        return baseMapper.selectNotifyRemindRecordList(query);
    }

    /**
     * 删除通知中心-用户通知记录信息
     * 
     * @param id 通知中心-用户通知记录主键
     * @return 结果
     */
    @Override
    public Integer deleteNotifyRemindRecordById(String id)
    {
        //根据id查询是否存在
        NotifyRemindRecordVO notifyRemindRecordVO=baseMapper.selectNotifyRemindRecordById(id);
        if(notifyRemindRecordVO==null){
            throw new BusinessException(ResultCodeEnum.PARAMETER_ERROR_CUSTOM,"id");
        }
        return baseMapper.deleteNotifyRemindRecordById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRES_NEW)
    public Integer insertBatch(List<NotifyRemindRecord> list) {
        return baseMapper.insertBatch(list);
    }

    @Override
    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRES_NEW)
    public Integer updateSendStatusBatch(UpdateNotifyRemindRecordDTO params) {
        return baseMapper.updateSendStatusBatch(params);
    }
}
